import requests
from common.token_data import TokenTool


def inquire_role_id(inquire_role_name):
    pag_num = 1
    while True:
        try:
            resp = requests.get(f"https://heimahr.itheima.net/api/sys/role?page={pag_num}&pagesize=5",
                                headers=TokenTool.token_data())
            data = resp.json().get("data").get("rows")
        except Exception as e:
            return print("请求失败", e)
        if not data:
            return "未找到该角色"

        for i in data:
            print(i)
            if i.get("name") == inquire_role_name:
                return i.get("id")
        pag_num += 1


if __name__ == '__main__':
    resp = inquire_role_id("测试角色")
    print(resp)
